/*
 * event.cpp
 *
 *  Created on: 03.05.2011
 *      Author: inkooboo
 */

#include "core/event.hpp"

#include <boost/property_tree/info_parser.hpp>
#include <boost/uuid/uuid_io.hpp>

#include <sstream>
#include <string>
#include <algorithm>

event_t::event_t(event_types_t type, const boost::uuids::uuid &who_is) :
    type_(static_cast<int>(type)), who_is_(who_is)
{
}

event_t::event_t()
{
}

event_t::event_t(std::istream &source)
{
    source >> type_;
    source >> who_is_;
    boost::property_tree::read_info(source, tree_);
}

std::string event_t::serialize() const
{
    std::ostringstream stream;
    stream << type_ << std::endl;
    stream << boost::uuids::to_string(who_is_) << std::endl;
    boost::property_tree::write_info(stream, tree_);
    return stream.str();
}

boost::property_tree::ptree &event_t::params()
{
    return tree_;
}

const event_types_t event_t::type() const
{
    return static_cast<event_types_t>(type_);
}

const boost::uuids::uuid &event_t::who_is() const
{
    return who_is_;
}

